<template>
    <div class="tabs">
        <el-tag v-for="tag in tags" :key="tag.path" :closable="tag.name !== 'home'"
            :effect="$route.name === tag.name ? 'dark' : 'plain'" @click="changroute(tag)" @close="handleClose(tag)">
            {{ tag.label }}
        </el-tag>
    </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
    name: 'CommomTag',
    data() {
        return {

        }
    },
    computed: {
        ...mapState({
            tags: state => state.tab.tabList
        })
    },
    methods: {
        changroute(tag) {
            this.$router.push(tag)
        },
        handleClose(tag) {
            if (this.$route.name == tag.name) {
                this.$router.push('/home')
            }
            this.$store.commit('deletMenu', tag)
        }

    }

}
</script>

<style lang="less" scoped>
.tabs {
    margin: 40px 0 10px 10px;

    .el-tag {
        margin-left: 10px;

        &:hover {
            cursor: pointer;
        }
    }
}
</style>